package com.moleq.dialog;

import android.content.Context;
import android.content.DialogInterface.OnDismissListener;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;

import com.moleq.mgpos.activities.R;

public class BaseDailog implements IBaseDialog {

	private LayoutParams LP_FF = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
	private PopupWindow mPopupWindow;
	public Context mContext;
	private LayoutInflater mInflater;
	private boolean mIsShowing = false;
	private int mWidth = 800;
	private int mHeight = 600;
	private View mView;
	private int mParentResID = R.layout.activity_sale;
	private LinearLayout layout;

	public BaseDailog(Context context, int layoutResID, int parentResID, Context context2) {
		// TODO Auto-generated constructor stub
		constructor(context, layoutResID, parentResID);
	}

	public BaseDailog(Context context, int layoutResID, int parentResID) {
		// TODO Auto-generated constructor stub
		constructor(context, layoutResID, parentResID);
	}

	public BaseDailog(Context context, int layoutResID, int parentResID, int width, int height) {
		mWidth = width;
		mHeight = height;
		constructor(context, layoutResID, parentResID);
	}

	public void constructor(Context context, int layoutResID, int parentResID) {
		mContext = context;
		mParentResID = parentResID;
		mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		mView = mInflater.inflate(layoutResID, null);

		layout = new LinearLayout(context);

		// 鍗婇�鏄庢晥鏋�
//		ColorDrawable dw = new ColorDrawable(-00000);
//		mView.setBackgroundDrawable(dw);

		layout.setGravity(Gravity.CENTER_VERTICAL);
		layout.setBackgroundColor(Color.parseColor("#b0000000"));
		layout.setLayoutParams(LP_FF);
		layout.setOrientation(LinearLayout.VERTICAL);
		layout.addView(mView);

	}

	public View findViewById(int id) {
		return mView.findViewById(id);
	}

	@Override
	public boolean isShowing() {
		return mIsShowing;
	}

	@Override
	public void setOnDismissListener(OnDismissListener paramOnDismissListener) {
		// TODO Auto-generated method stub

	}

	@Override
	public void dismiss() {
		if (mPopupWindow.isShowing()) {
			mPopupWindow.dismiss();
			mIsShowing = false;
		}
	}

	@Override
	public void show() {
		if (mPopupWindow == null) {
			mPopupWindow = new PopupWindow(layout, mWidth, mHeight);
			mPopupWindow.setFocusable(true);
			mPopupWindow.update();
		}
		if (!mPopupWindow.isShowing()) {
			resetItemDisplayInfo();
			mPopupWindow.showAtLocation(mInflater.inflate(mParentResID, null), Gravity.CENTER_VERTICAL, 0, 0);
			mIsShowing = true;
		}

	}

	private void resetItemDisplayInfo() {
		// TODO Auto-generated method stub

	}

}
